package com.atguigu.yygh.sms.listener;

import com.atguigu.yygh.rabbitmq.constant.RabbitMQConstant;
import com.atguigu.yygh.sms.service.SMSService;
import com.atguigu.yygh.vo.msm.MsmVo;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author:hx
 * @DateTime:2022/11/18 18:36
 * @Description:
 */
@Component
public class SMSListener {

    @Autowired
    private SMSService smsService;

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(value = RabbitMQConstant.QUEUE_SMS),
                    exchange = @Exchange(value = RabbitMQConstant.EXCHANGE_DIRECT_SMS),
                    key = {RabbitMQConstant.ROUTING_SMS}
            )
    })
    public void listenMessage(MsmVo msmVo, Message message, Channel channel){
        smsService.sendMessage(msmVo);
    }
}
